package com.skzh.equipment.service.impl;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.skzh.common.exception.ServiceException;
import com.skzh.common.utils.DateUtils;
import com.skzh.equipment.mapper.DockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.skzh.equipment.mapper.DockConfigMapper;
import com.skzh.equipment.domain.DockConfig;
import com.skzh.equipment.service.IDockConfigService;

/**
 * 机场设置Service业务层处理
 *
 * @author skzh
 * @date 2025-03-24
 */
@Service
public class DockConfigServiceImpl implements IDockConfigService {
    @Autowired
    private DockConfigMapper dockConfigMapper;
    @Autowired
    private DockMapper dockMapper;

    /**
     * 查询机场设置
     *
     * @param id 机场设置主键
     * @return 机场设置
     */
    @Override
    public DockConfig selectDockConfigById(Long id) {
        return dockConfigMapper.selectDockConfigById(id);
    }

    /**
     * 查询机场设置列表
     *
     * @param dockConfig 机场设置
     * @return 机场设置
     */
    @Override
    public List<DockConfig> selectDockConfigList(DockConfig dockConfig) {
        return dockConfigMapper.selectDockConfigList(dockConfig);
    }

    /**
     * 新增机场设置
     *
     * @param dockConfig 机场设置
     * @return 结果
     */
    @Override
    public int insertDockConfig(DockConfig dockConfig) {
        dockConfig.setCreateTime(DateUtils.getNowDate());
        return dockConfigMapper.insertDockConfig(dockConfig);
    }

    /**
     * 修改机场设置
     *
     * @param dockConfig 机场设置
     * @return 结果
     */
    @Override
    public int updateDockConfig(DockConfig dockConfig) {
        if (dockConfig.getWorkRange() < 0) {
            throw new ServiceException("作业范围不能设置为负数");
        }
        if (dockConfig.getReturnWindSpeed()<0){
            throw new ServiceException("自动返航风速不能设置为负数");
        }
        if (dockConfig.getReturnRainfall()==null){
            throw new ServiceException("请选择阻飞、自动返航雨量/雪量");
        }
        dockConfig.setUpdateTime(DateUtils.getNowDate());
        return dockConfigMapper.updateDockConfig(dockConfig);
    }

    /**
     * 批量删除机场设置
     *
     * @param ids 需要删除的机场设置主键
     * @return 结果
     */
    @Override
    public int deleteDockConfigByIds(Long[] ids) {
        return dockConfigMapper.deleteDockConfigByIds(ids);
    }

    /**
     * 删除机场设置信息
     *
     * @param id 机场设置主键
     * @return 结果
     */
    @Override
    public int deleteDockConfigById(Long id) {
        return dockConfigMapper.deleteDockConfigById(id);
    }

    @Override
    public DockConfig selectDockConfigByDockId(Long dockId) {
        return dockConfigMapper.selectDockConfigByDockId(dockId);
    }

    @Override
    public List<Map<Object, Object>> selectAllDockName() {
        return dockMapper.selectAllDockName();
    }
}
